package api

import (
	"github.com/gin-gonic/gin"
	"zimuzu_cvn_web_api/pkg/errno"
	"net/http"

	. "zimuzu_cvn_web_api/pkg/e"
)

type HttpResponse struct {
	Status int         `json:"status"`
	Info   string      `json:"info"`
	Data   interface{} `json:"data"`
}

func SendResponse(c *gin.Context, err error, data interface{}) {
	status, info := errno.DecodeErr(err)
	if err != nil && status != 1 {
		Log("Warn", err.Error())
	}
	c.JSON(http.StatusOK, HttpResponse{
		Status: status,
		Info:   info,
		Data:   data,
	})
}
